/*
  学习目标：动态路由
*/

import React from 'react';
import { BrowserRouter as Router, NavLink, Redirect, Route, Switch, Link } from 'react-router-dom';
import './base.css';

export default class App extends React.Component {
  render() {
    return (
      <Router>
        <div>
          <h1>app组件</h1>
          <NavLink activeClassName="xxx" to="/home">
            首页
          </NavLink>
          <br />
          <NavLink activeClassName="xxx" to="/my">
            我的音乐
          </NavLink>
          <br />
          <NavLink activeClassName="xxx" to="/friend" exact>
            朋友
          </NavLink>
          <Switch>
            <Redirect from="/" to="/home" exact />
            <Route path="/home" component={Home} />
            {/* 1. 改造动态路由: /路径/:自定义参数 */}
            <Route path="/my/:xxx" component={MyMusic} />
            <Route path="/friend" component={Friend} />
          </Switch>
        </div>
      </Router>
    );
  }
}

function Friend({ history }) {
  return (
    <>
      <h1>我是朋友组件</h1>
      <button
        onClick={() => {
          history.go(1); // 前进一步
        }}
      >
        点我跳转
      </button>
    </>
  );
}

function Home() {
  return <h1>我是首页组件</h1>;
}

function MyMusic({ match }) {
  console.log('match.params.xxx  ----->  ', match.params.xxx);
  // 2. props.match.params.自定义属性名 获取
  return <h1>我是我的音乐件 - {match.params.xxx}</h1>;
}
